//
//  BusinessSystemConfig.h
//  MyPorject
//
//  Created by Tzl on 2021/1/20.
//  业务配置

#import <UIKit/UIKit.h>
#import <sys/utsname.h>//获取手机型号
#import <Foundation/Foundation.h>

#import <SwiftyFitsize.h>
#import <SwiftyFitsize-Swift.h>


#ifndef BusinessSystemConfig_h
#define BusinessSystemConfig_h

///极光Key
NS_INLINE NSString *JpushKey(){
    return @"492cd2d7263ccf46e578fd6e";
}

///比例
NS_INLINE CGFloat Scale(){
    return [[SwiftyFitsize sharedSwiftyFitsize] sf_float:1.0f];
}
/// 屏幕宽度
NS_INLINE CGFloat ScreenWith(){
    return [UIScreen mainScreen].bounds.size.width;
}

/// 屏幕高度
NS_INLINE CGFloat ScreenHeight(){
    return [UIScreen mainScreen].bounds.size.height;
}

/// 安全区域高度
NS_INLINE CGFloat BottomSafeAreaHeight(){
    return  ([[UIApplication sharedApplication] statusBarFrame].size.height>20.0f ? 34.0f : 0);
}

/// tabBar高度
NS_INLINE CGFloat TabBarHeight(){
    return BottomSafeAreaHeight() + 49.0f;
}

///导航栏高度
NS_INLINE CGFloat NavgitionHeight(){
    ///iphoneX以下为64 iphone X 为88，iphone 11为92， iphone12为91
    return [[UIApplication sharedApplication] statusBarFrame].size.height + 44.0f;
}

///状态栏高度
NS_INLINE CGFloat StateBarHeight(){
    return UIApplication.sharedApplication.statusBarFrame.size.height;
}

//获取当前版本号
NS_INLINE NSString *GetCurrentVersion(){
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    // app版本
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    return app_Version;
}

/**
 16进制颜色
 @param hex 16进制值
 @param alpha 透明度
 @return UIcolor类型 颜色
 */
NS_INLINE UIColor *ColorHex(NSInteger hex , CGFloat alpha){
    return [UIColor colorWithRed:(((hex & 0xFF0000) >> 16))/255.0 green:(((hex & 0xFF00) >>8))/255.0 blue:((hex & 0xFF))/255.0 alpha:alpha];
}


/** 为了 colorHex使用 **/
NS_INLINE NSInteger numberOfHexColor(NSString *hexColorStr){
    if ([hexColorStr containsString:@"#"]) {
        hexColorStr = [hexColorStr stringByReplacingOccurrencesOfString:@"#" withString:@""];
    }
    const char *hexChar = [hexColorStr cStringUsingEncoding:NSUTF8StringEncoding];
    int hexNumber;
    sscanf(hexChar, "%x", &hexNumber);
    return (NSInteger)hexNumber;
}

/** 颜色色值 hexStr **/
NS_INLINE UIColor *colorHex(NSString *hexStr){
    NSInteger hex = numberOfHexColor(hexStr);
    return [UIColor colorWithRed:(((hex & 0xFF0000) >> 16))/255.0 green:(((hex & 0xFF00) >>8))/255.0 blue:((hex & 0xFF))/255.0 alpha:1.0];
}

/**  字符串格式化  **/
NS_INLINE NSString *FormatStr(NSString *str){
    str =  [NSString stringWithFormat:@"%@",str];
    if (str == nil || //为nil
        [str isEqualToString:@"<null>"] ||
        [str isEqualToString:@"(null)"] ||
        [str isEqualToString:@"null"] ||
        [str isEqualToString:@""] || //为@”“
        str.length == 0 || //长度
        [str stringByReplacingOccurrencesOfString:@" " withString:@""].length == 0 //替换了空格后的长度
        )
    {
        str = @"";
    }
    return [NSString stringWithFormat:@"%@",str];
}

/// 字体大小
/// @param size 字体大小
/// @param weight 比重
NS_INLINE UIFont *BoldFontWith(CGFloat size , UIFontWeight weight){
    return [UIFont systemFontOfSize:size*Scale() weight:weight];
}


/**  tableView适配 iOS11  **/
NS_INLINE void FitiOS11(UITableView *mainTab){
    if (@available(iOS 11.0, *)) {
        UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        mainTab.estimatedRowHeight = 0;
        mainTab.estimatedSectionHeaderHeight = 0;
        mainTab.estimatedSectionFooterHeight = 0;
    }
}


/**  手机的型号等  **/
NS_INLINE NSString *PhoneSystem(){
    struct utsname systemInfo;
    uname(&systemInfo);
    NSString*platform = [NSString stringWithCString: systemInfo.machine encoding:NSASCIIStringEncoding];
    if([platform isEqualToString:@"iPhone1,1"])  return @"iPhone 2G";
    if([platform isEqualToString:@"iPhone1,2"])  return @"iPhone 3G";
    if([platform isEqualToString:@"iPhone2,1"])  return @"iPhone 3GS";
    if([platform isEqualToString:@"iPhone3,1"])  return @"iPhone 4";
    if([platform isEqualToString:@"iPhone3,2"])  return @"iPhone 4";
    if([platform isEqualToString:@"iPhone3,3"])  return @"iPhone 4";
    if([platform isEqualToString:@"iPhone4,1"])  return @"iPhone 4S";
    if([platform isEqualToString:@"iPhone5,1"])  return @"iPhone 5";
    if([platform isEqualToString:@"iPhone5,2"])  return @"iPhone 5";
    if([platform isEqualToString:@"iPhone5,3"])  return @"iPhone 5c";
    if([platform isEqualToString:@"iPhone5,4"])  return @"iPhone 5c";
    if([platform isEqualToString:@"iPhone6,1"])  return @"iPhone 5s";
    if([platform isEqualToString:@"iPhone6,2"])  return @"iPhone 5s";
    if([platform isEqualToString:@"iPhone7,1"])  return @"iPhone 6 Plus";
    if([platform isEqualToString:@"iPhone7,2"])  return @"iPhone 6";
    if([platform isEqualToString:@"iPhone8,1"])  return @"iPhone 6s";
    if([platform isEqualToString:@"iPhone8,2"])  return @"iPhone 6s Plus";
    if([platform isEqualToString:@"iPhone8,4"])  return @"iPhone SE";
    if([platform isEqualToString:@"iPhone9,1"])  return @"iPhone 7";
    if([platform isEqualToString:@"iPhone9,3"])  return @"iPhone 7";
    if([platform isEqualToString:@"iPhone9,2"])  return @"iPhone 7 Plus";
    if([platform isEqualToString:@"iPhone9,4"])  return @"iPhone 7 Plus";
    if([platform isEqualToString:@"iPhone10,1"]) return @"iPhone 8";
    if([platform isEqualToString:@"iPhone10,4"]) return @"iPhone 8";
    if([platform isEqualToString:@"iPhone10,2"]) return @"iPhone 8 Plus";
    if([platform isEqualToString:@"iPhone10,5"]) return @"iPhone 8 Plus";
    if([platform isEqualToString:@"iPhone10,3"]) return @"iPhone X";
    if([platform isEqualToString:@"iPhone10,6"]) return @"iPhone X";
    if([platform  isEqualToString:@"iPhone11,8"]) return @"iPhone XR";
    if([platform  isEqualToString:@"iPhone11,2"]) return @"iPhone XS";
    if([platform  isEqualToString:@"iPhone11,4"]) return @"iPhone XS Max";
    if([platform  isEqualToString:@"iPhone11,6"]) return @"iPhone XS Max";
    if ([platform isEqualToString:@"iPhone12,1"])  return @"iPhone 11";
    if ([platform isEqualToString:@"iPhone12,3"])  return @"iPhone 11 Pro";
    if ([platform isEqualToString:@"iPhone12,5"])  return @"iPhone 11 Pro Max";
    if ([platform isEqualToString:@"iPhone13,1"]) return @"iPhone 12 mini";
    if ([platform isEqualToString:@"iPhone13,2"]) return @"iPhone 12";
    if ([platform isEqualToString:@"iPhone13,3"]) return @"iPhone 12 Pro";
    if ([platform isEqualToString:@"iPhone13,4"]) return @"iPhone 12 Pro Max";
    return [UIDevice currentDevice].name;
    
}

/**  颜色配置  **/
///界面背景色
NS_INLINE UIColor *BgViewColor(){
    return ColorHex(0xf3f3f3, 1);
}

///主题色
NS_INLINE UIColor *PrimaryColor(){
    return ColorHex(0xffbb00, 1);
}



/**  字体大小配置  **/
///加粗字体
NS_INLINE UIFont *BoldTitleFontWith(CGFloat size){
    return BoldFontWith(size, UIFontWeightBold);
}
///粗标题
NS_INLINE UIFont *HeavyTitleFont(CGFloat size){
    return BoldFontWith(size, UIFontWeightHeavy);
}
///中粗标题
NS_INLINE UIFont *MediumTitleFont(CGFloat size){
    return BoldFontWith(size, UIFontWeightMedium);
}
///常规标题
NS_INLINE UIFont *RegularTitleFont(CGFloat size){
    return BoldFontWith(size, UIFontWeightRegular);
}


///用户表
NS_INLINE NSString *UserTab(){
    return @"JTCUSERMODEL";
}

///登录成功
NS_INLINE NSString *LOGINSUCCESS(){
    return @"LOGINSUCCESS";
}

/**
 判断是不是空字符串
 @param checkStr 待判断参数
 @return Bool，YES为空，NO不为空
 */
NS_INLINE BOOL isEmptyStr(NSString *checkStr){
    return ([checkStr isKindOfClass:[NSNull class]] || !checkStr || [checkStr isEqualToString:@""] || [checkStr isEqualToString:@"<null>"]||[checkStr isEqualToString:@"null"]||[checkStr isEqualToString:@"(null)"]|| [checkStr isEqualToString:@" "] || ([checkStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length == 0));
}

#endif /* BusinessSystemConfig_h */
